/************************************************************** **/
/**调用服务器端的JS文件,包含所用的调用服务器后端的JS示例　　　　**/
/************************************************************** **/
import Common from './common/common.js';
import Config from './config/config.js';

const Base_Url = Config.ServerBaseUrl;

const logger = Common.log("ServiceNet");

const post = (url, param, success, error) => {
    $.post(Base_Url + url, param, (d) => {
        let info = "[" + url + "] param:(" + JSON.stringify(param) + ")";
        if (!d.status　||　d.status == "S") {
            logger.debug("[响应]" + info, d);
            if (success) {
                success(d);
            }
        } else {
            logger.error("[响应]" + info, d);
            if (error) {
                error(d)
            }
        }

    });
}



export default {
    /*登录服务器换取用于TIM操作的userSig密码*/
    login: function (userId, password, success, error) {
        post("user/userLogin", {userId: userId, password:password}, success, error);
    },
    /*获取好友列表*/
    getFriendList: function (startIndex, success) {
        post("friend/queryFriendByPage", {startIndex: startIndex}, success);
    },
    /*用户模糊查询*/
    queryUserLike:function(key,success){
        post("user/queryUserLike", {key: key}, success);
    },
    /*添加好友*/
    addFriend:function(friendUserId,remark,success){
        post("friend/addFriend", {friendUserId: friendUserId,remark:remark}, success,(d)=>{
            alert(d.sysMsg)
        });
    },
    /*删除好友*/
    delFriend:function(friendUserId,success){
        post("friend/deleteFirend", {friendUserId: friendUserId}, success);
    }
};
